package py.com.alfa.escriba.gui.controller.object.referencia;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;

import py.com.alfa.escriba.gui.config.EscribaGUIApplicationContextProvider;
import py.com.alfa.escriba.gui.controller.view.Permissions;
import py.com.alfa.escriba.gui.controller.view.View;
import py.com.alfa.escriba.gui.controller.view.ViewManager;
import py.com.alfa.escriba.gui.controller.view.referencia.BarriosViewContext;
import py.com.alfa.escriba.gui.controller.view.referencia.BarriosViewFragment;
import py.com.alfa.escriba.gui.dto.admin.BarrioDTO;
import py.com.alfa.escriba.gui.dto.admin.DistritoDTO;
import py.com.alfa.escriba.gui.services.Services;


public class BarriosControllerObject {

	private List<BarrioDTO> barrios;
	private BarrioDTO barrio;
	private DistritoDTO distrito;
	private ViewManager viewManager;
	private String titulo = "";
	
	public BarriosControllerObject() {
		ApplicationContext ctx = EscribaGUIApplicationContextProvider.getContext();
		this.setBarrios(new ArrayList<BarrioDTO>());
		this.setViewManager((ViewManager) ctx.getBean(Services.VIEW_MANAGER));
		this.getViewManager().registerContext(View.BARRIOS, new BarriosViewContext());
	}

	public BarriosViewFragment view(){
		return (BarriosViewFragment) this.getContext().getViewFragment();
	}

	public BarriosViewContext getContext(){
		return (BarriosViewContext) getViewManager().getContext(View.BARRIOS);
	}
	
	public Permissions getPermissions(){
		return getViewManager().getPermissions();
	}

	public List<BarrioDTO> getBarrios() {
		return this.barrios;
	}

	public void setBarrios(List<BarrioDTO> barrios) {
		this.barrios = barrios;
	}

	public BarrioDTO getBarrio() {
		if ( this.barrio == null ) {
			this.barrio = new BarrioDTO();
		}
		return this.barrio;
	}

	public void setBarrio(BarrioDTO barrio) {
		this.barrio = barrio;
	}

	public DistritoDTO getDistrito() {
		return distrito;
	}

	public void setDistrito(DistritoDTO distrito) {
		this.distrito = distrito;
	}

	public ViewManager getViewManager() {
		return viewManager;
	}

	public void setViewManager(ViewManager viewManager) {
		this.viewManager = viewManager;
	}

	public String getTitulo() {
		return titulo;
	}

	public void setTitulo(String titulo) {
		this.titulo = titulo;
	}

}
